package com.me.Inheritor;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;



// Manages and updates ControllerObjects
public class ObjectManager 
{
	public enum ObjectType { OT_Player,OT_Enemy,OT_Platform };
	
	int		nMaxObjects;
	ArrayList<ControllerObject>	objects;
	TextureManager		texMan;
	LevelGenerator		levelGen;
	
	public ObjectManager()
	{
		nMaxObjects	= 100;
		objects		= new ArrayList<ControllerObject>();
		texMan		= new TextureManager();
		levelGen	= new LevelGenerator();
		
		GameData.setTextureManager( texMan );
	}
	
	public void Update( float dt )
	{
		levelGen.Update( dt );
		GameData.getPlayer().Update( dt );
		
		for( int i = 0;i < objects.size();++i )
		{
			objects.get(i).Update( dt );
		}
	}
	public void Render( SpriteBatch batch )
	{
		for( int i = 0;i < objects.size();++i )
		{
			objects.get(i).Render(batch);
		}
		
		GameData.getPlayer().Render( batch );
	}
	
	public ControllerObject CreateObject( ObjectType type )
	{
		ControllerObject obj = null;
		
		switch( type )
		{
		case OT_Player:
			obj = new Player();
			break;
		case OT_Enemy:
			obj = new Enemy();
			break;
		case OT_Platform:
			obj = new Platform();
			break;
		}
		
		if( obj != null )
			objects.add( obj );
		
		return obj;
	}
	public ControllerObject CreateObject( ObjectType type,boolean AddToManager )
	{
		ControllerObject obj = null;

		switch( type )
		{
		case OT_Player:
			obj = new Player();
			break;
		case OT_Enemy:
			obj = new Enemy();
			break;
		case OT_Platform:
			obj = new Platform();
			break;
		}
		
		if( obj != null && AddToManager )
			objects.add( obj );
		
		return obj;
	}
	public boolean AddObject( ControllerObject obj )
	{
		if( objects.size() < 100 )
		{
			obj.setID( objects.size() );
			objects.add( obj );
			return true;
		}
		
		return false;
	}
	public void RemoveObject( ControllerObject obj )
	{
		objects.remove( obj );
	}
	
	public void Dispose()
	{
		objects.clear();
	}
}
